<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>IIFE（优化）</title>
</head>
<body>
    <!-- IIFE（优化）：引入依赖 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
    <script>
        (function(window, $) {
            let data = '我是模块A中的数据'
                function fn1() {
                    console.log(`我是fn1打印的${data}`)
                }
                function fn2() {
                    console.log(`我通过fn2修改了data数据`)
                }
                function fn3() {
                    console.log(`我访问了jQuery${$}，并改变了body的颜色`)
                    $('body').css('background', '#bfa')
                }
                window.moduleA = {
                    fn1,
                    fn2,
                    fn3
                }
        })(window, jQuery)
        window.moduleA.fn3()
    </script>
</body>
</html>